// pages/reward/resume/details.js
import { $wuxDialog } from '../../../wux-components/index'
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = '';
let userId = -1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: -1,
    origin: '',
    recommendClassifyId: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = Number(options.id);

    this.data.recommendClassifyId = options.recommendClassifyId ? options.recommendClassifyId : 0;

    if (options.origin == 'recommend') {
      this.setData({ origin: 'recommend' });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    token = getApp().globalData.token;
    userId = getApp().globalData.userId;
    this.getDetail();
  },

  getDetail() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'reward/resume_list/detail',
      method: 'GET',
      data: {
        token: token,
        rewardId: this.data.id
      },
      success: (res) => {
        this.setData({
          userObj: res,
          job: res.jobIntension,
          work: res.workExperience,
          school: res.schoolExperience
        })
      }
    })
  },

  // 我要推荐 - 简历
  onRecommend(e) {
    $wuxDialog().confirm({
      resetOnClose: true,
      closable: true,
      title: '提示',
      content: '内容--todo',
      onConfirm: (e) => {
        let param = {
          reAvator: encodeURIComponent(getApp().globalData.userInfo.avator),
          reName: getApp().globalData.userInfo.name,
          reedAvator: encodeURIComponent(this.data.userObj.headImg),
          reedName: this.data.userObj.name,
          reedSex: this.data.userObj.sex == 1 ? '男' : '女',
          reedAge: this.data.userObj.age + '岁',
          reedEdu: e.currentTarget.dataset.edu,
          reedWork: this.data.userObj.workYear + '年工作经验',
          reedPos: this.data.job.positionName,
          reedSalary: this.data.job.salaryRange
        };

        // 调接口给添加推荐记录
        const paramRecommend = {
          token: token,
          userId: userId,
          userType: 1,  // 0-应聘用户 1-招聘用户
        };
        T.req({
          loadTitle: '加载中...',
          url: config.api + 'recommendation/resume/' + this.data.id + '?' + T.param(paramRecommend),
          method: 'POST',
          data: {},
          success: (res) => {
            param.rewardId = this.data.id;  // 悬赏 id
            param.recommendClassifyId = res.recommendClassifyId;  // 推荐编号
            param.url = 'pages/reward/resume/resume';

            wx.navigateTo({
              url: '/pages/poster/resume/resume?' + T.param(param),
            })
          }
        })
      },
      onCancel(e) {

      },
    })
  },


  // 预约简历
  onMakeResume() {
    let obj = { 
      recommendClassifyId: this.data.recommendClassifyId,
      candidateId: this.data.id, 
      resumeId: this.data.resumeId, 
      type: 0 
    }
    wx.navigateTo({
      url: '../order/order?' + T.param(obj),
    })  
  }

})